Imports System.Data.SqlClient

Friend Class DBField_Factory
    Inherits DBBase

    Public Function GetAllFieldsForTable( _
                        ByVal lTableID As Long, _
                        ByVal lTableRevID As Long) As ArrayList

        Dim oList As New ArrayList

        Dim sSQL As String = "select"
        sSQL = sSQL & "     a.[ID]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     tDDFields a"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     a.[TableID]=" & ValueToDBValue(lTableID)
        sSQL = sSQL & "     and a.[TableRevID]=" & ValueToDBValue(lTableRevID)
        sSQL = sSQL & " order by"
        sSQL = sSQL & "     a.[Order]"

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        For Each oRow As DataRow In oData.Rows
            Dim oField As New SQLAutoDocLib.Field(oRow.Item(0))
            oField.Load()

            oList.Add(oField)
        Next

        oData.Dispose()

        Return oList
    End Function

    Public Function GetFieldByName( _
                        ByVal lTableID As Long, _
                        ByVal sField As String) As SQLAutoDocLib.Field

        Dim oField As SQLAutoDocLib.Field = Nothing

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [ID]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     tDDFields"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [TableID]=" & ValueToDBValue(lTableID)
        sSQL = sSQL & "     and [Name]=" & ValueToDBValue(sField)

        Dim oValue As Object = MyBase.ExecuteScalar(sSQL)

        If IsNumeric(oValue) Then
            oField = New SQLAutoDocLib.Field(CLng(oValue))
            oField.Load()
        End If

        Return oField
    End Function
End Class
